package com.waverider.promotion.web.bg.screen;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;

import com.iacrqq.util.StringUtil;
import com.waverider.promotion.biz.manager.ItemManager;
import com.waverider.promotion.web.AbstractLoginedController;

public class Promotion extends AbstractLoginedController
{
	
	private ItemManager itemManager;
	
	@Override
	protected ModelAndView handleLogined(HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		HttpSession session = request.getSession();
		ModelAndView mv = new ModelAndView("bg/promotion");
		Long promotionId = null;
		String strPromotionId = request.getParameter("promotion_id");
		if(!StringUtil.isBlank(strPromotionId))
		{
			// 修改
			promotionId = Long.valueOf(strPromotionId);
			mv.getModel().put("promotion", itemManager.getPromotionById(promotionId));
		}
		else
		{
			// 新增
			mv.getModel().put("item", itemManager.getItem(getSessionKey(session), Long.valueOf(request.getParameter("item_id"))));
		}
		 
		
		return mv;
	}

	public void setItemManager(ItemManager itemManager)
	{
		this.itemManager = itemManager;
	}
}
